jQuery.extend({
    getNum: function (min, max) {
        return parseInt(Math.random() * (max - min + 1) + min, 10)
    },
    getCounterQuestion: function (min, max) {
        var n = $.getNum(min, max);
        if (n < 10) n += 10;
        if (n % 10 === 0) n += 2;
        var a = parseInt(n / 10);
        var b = n % 10;
        var x = $.getNum(0, 10);
        var l = $.getNum(0, questList.length - 1)
        return (questList[l] + "").replaceAll("N", n + "").replaceAll("A", a + "").replaceAll("B", b + "")
            .replaceAll("X", x + "");
    }
})

(function ($) {
    $.fn.extend({
        addition3: function (num) {
            var h = ""
            for (var i = 0; i < num; i++) {
                var a = $.getNum(6, 9);
                var b = $.getNum(3, 7);
                var c = $.getNum(2, 8)
                var e = "+";
                if (a + b > c) {
                    var d = $.getNum(0, 1);
                    if (d === 0) {
                        e = "-"
                    }
                }

                h += "<div class='t2'>" + a + "+" + b + e + c + "= </div>";
            }
            return this.append("<div style='float: left;padding-bottom:15px'>" + h + "</div>");
        },
        counter: function (num, min, max) {
            if (!min) min = 11;
            if (!max) max = 99;
            var s = "";
            for (var i = 0; i < num; i++)
                s += (i + 1) + ". " + $.getCounterQuestion(min, max) + "\n";
            return this.append("<div style='font-size: 18px; line-height:22px' ><pre style='line-height: 34px'>" + s + "</pre></div>");
        },
        shizi: function (num) {
            zi.sort(function () {
                return 0.5 - Math.random();
            }).sort(function () {
                return 0.5 - Math.random();
            })
            var h = "";
            for (var i = 0; i < num; i++) {
                h += "<div class='zu'>";
                h += "<div class='pinyinge'></div>";
                h += "<div class='hanzi'>" + zi[i].zi + "</div>";
                h += "</div>";
            }
            $(this).append("<div style='float: left;'>" + h + "</div>");
        },
        xiezi: function (num) {
            var n = [];
            for (var i = 0; i < zi.length; i++) {
                if (zi[i].xie == 1) {
                    n.push(zi[i]);
                }
            }
            n.sort(function () {
                return 0.5 - Math.random();
            }).sort(function () {
                return 0.5 - Math.random();
            })
            h = "";
            for (var i = 0; i < num; i++) {

                var ci = (Math.round(Math.random()) === 1) ? n[i].zuci1 : n[i].zuci2;
                var z = n[i].zi;
                var p = n[i].pinyin;
                if (ci.length == 4) {
                    h += "<div class='zu' style='width: 260px'>"
                } else {
                    h += "<div class='zu'>"
                }

                for (let j of ci) {
                    if (j == z) {
                        h += "            <div class=\"zu1\" style=\"float: left\">\n" +
                            "                    <div class=\"pinyin\">" + p + "</div>\n" +
                            "                    <div class=\"tianzige\"></div>\n" +
                            "                </div>\n";
                    } else {
                        h += "            <div class=\"zu1\" style=\"float: left\">\n" +
                            "                    <div class=\"pinyin\"></div>\n" +
                            "                    <div class=\"tianzige\">" + j + "</div>\n" +
                            "                </div>\n";
                    }
                }
                h += "</div>"


            }


            $(this).append("<div style='float: left;padding-bottom:15px'>" + h + "</div>");
        }

    })
})